<?php

/**
 * uniBoard ACP User Ranks
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-08 03:38:35 +0000 (Wed, 08 Sep 2010) $
 * $Revision: 60 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class action_ranks{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	// ------------------------------------------------------------------------

	/**
	 * Initialise Action
	 *
	 * @param object $appCore
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
		
		// Add language string
		$appCore -> output -> js_vars['l_delete_item_sure'] = $appCore -> lang['delete_item_sure'];
		
		// Cache output
		ob_start();
		
		// Open table block
		echo $appCore -> output -> openTableBlock();
		
		// Draw header
		echo $appCore -> output -> tableHeader( array(
			array(
				'left_float width_big',
				$appCore -> lang['acp_ranks_list_rank']
			),
			array(
				'right_float width_medium',
				$appCore -> lang['actions']
			),
			array(
				'right_float width_big',
				$appCore -> lang['acp_ranks_list_posts']
			)
		));
				
		// Select Ranks
		$appCore -> db -> query( 'SELECT *
		FROM ' . DB_PREFIX . 'user_ranks
		ORDER BY rank_special DESC, rank_posts DESC');
		
		// Parse result
		while ( $rank_result = $appCore -> db -> fetch_array())
		{
			// Rank Image
			$rank_image = ( isset($rank_result[4][0]) ? '<img src="' . IMAGES_PATH . htmlspecialchars( $rank_result[4]) . '" alt="" />' : $appCore -> output -> drawImage( 'pip'));
		
			// Translate Rank Image?
			if ( $appCore -> conf['board_int_ranks'])
			{
				$rank_image = str_replace( '{L}', $appCore -> user['language_iso']);
			}
			
			// Draw row
			echo $appCore -> output -> tableRow('
				<div class="cell left_float width_big">
					<b>' . ( $appCore -> conf['board_int_ranks'] ? $appCore -> ifString( htmlspecialchars( $rank_result[3])) : htmlspecialchars( $rank_result[3])) . '</b>
					<div>' . ( $rank_result[5] > 1 ? str_repeat( $rank_image, $rank_result[5]) : $rank_image) . '</div>
				</div>
				<div class="cell left_border right_float width_medium center">
					<a href="' . $appCore -> adminLink( 'act=edit_rank&do=edit&rank=' . $rank_result[0]) . '">' . $appCore -> output -> drawImage( 'action_edit', $appCore -> lang['edit']) . '</a>
<a href="' . $appCore -> adminLink( 'act=edit_rank&do=delete&rank=' . $rank_result[0]) . '" class="delete_confirm">' . $appCore -> output -> drawImage( 'action_delete', $appCore -> lang['delete']) . '</a>
				</div>
				<div class="cell left_border right_float width_big center">
					<b>' . ( $rank_result[1] ? '<i>' . $appCore -> lang['acp_ranks_list_special'] . '</i>' : $appCore -> number( $rank_result[2])) . '</b>
				</div>');
		}
		
		// Free result
		$appCore -> db -> freeResult();
		
		// Close table block
		echo $appCore -> output -> closeTableBlock();
		
		// New Rank Button
		echo $appCore -> output -> openForm( $appCore -> adminLink( 'act=new_rank'));
		echo $appCore -> output -> openFormBlock( $appCore -> lang['new_rank_form']);
		echo $appCore -> output -> submitButton( $appCore -> lang['new_rank_form_submit']);
		echo $appCore -> output -> closeFormBlock();
		echo $appCore -> output -> closeForm();
		
		// Draw output
		$appCore -> output -> draw( $appCore -> lang['acp_users_ranks'], array( $appCore -> adminLink( 'act=ranks') => $appCore -> lang['acp_users_ranks']), ob_get_clean());
				
	}

}